/*
 * Bullet.cpp
 *
 *  Created on: 02/05/2013
 *      Author: Vitor
 */

#include "Bullet.h"

Bullet::Bullet(Point position, Vector2 velocity, bool isEnemy,
		Sprite* bulletSprite) :
		GameObject(position, bulletSprite->getWidth(),
				bulletSprite->getHeight()) {
	this->bulletSprite = bulletSprite;
	this->velocity = velocity;
	this->enemy = isEnemy;
	this->speed = velocity.length();
	this->dead = false;
	this->angle =
			(atan2(-velocity.getY(), velocity.getX()) * 180 / M_PI) + 90;
}

Bullet::~Bullet() {
	// TODO Auto-generated destructor stub
}

int Bullet::update(double dt) {
	// Equivalente a posicao += velocidade
	this->box.setPosition(
			this->box.getPositionRef()->addVector(
					this->velocity.constantProduct(dt)));
	return 0;
}

void Bullet::render(float cameraX, float cameraY) {

	this->bulletSprite->rotoZoom(angle, 1, 1, false);
	bulletSprite->render(box.getPositionRef()->getX() - cameraX,
			box.getPositionRef()->getY() - cameraY, true);
}

